#pragma once
#include <iostream>
#include <memory>
#include <unordered_map>
#include "Epoller.hpp"
#include "Connection.hpp"
#include "Listener.hpp"

class TcpServer
{
public:
    TcpServer()
        :_epoller_ptr(std::make_unique<Epoller>())
    {

    }

    void Start()
    {
        while(true)
        {
            _epoller_ptr->Wait();
        }
    }

    void AddConnection(std::shared_ptr<Connection> &conn)
    {
        uint32_t events = conn->GetEvent();
        int sockfd = conn->GetFd();
        _epoller_ptr->AddEvent(sockfd,events);

        _connection[sockfd] = conn;
    }
private:
    std::unique_ptr<Epoller> _epoller_ptr;

    std::unordered_map<int,std::shared_ptr<Connection>> _connection;
};
